<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg10.php" ?>
<?php include_once "ewmysql10.php" ?>
<?php include_once "phpfn10.php" ?>
<?php include_once "movimientosinfo.php" ?>
<?php include_once "usuariosinfo.php" ?>
<?php include_once "userfn10.php" ?>
<?php

//
// Page class
//

$movimientos_edit = NULL; // Initialize page object first

class cmovimientos_edit extends cmovimientos {

	// Page ID
	var $PageID = 'edit';

	// Project ID
	var $ProjectID = "{320446D7-E035-4611-AE9B-94BD19ABA249}";

	// Table name
	var $TableName = 'movimientos';

	// Page object name
	var $PageObjName = 'movimientos_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		if ($this->UseTokenInUrl) $PageUrl .= "t=" . $this->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	function getWarningMessage() {
		return @$_SESSION[EW_SESSION_WARNING_MESSAGE];
	}

	function setWarningMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$hidden = FALSE;
		$html = "";

		// Message
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sMessage . "</div>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$sWarningMessage = $this->getWarningMessage();
		$this->Message_Showing($sWarningMessage, "warning");
		if ($sWarningMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sWarningMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sWarningMessage;
			$html .= "<div class=\"alert alert-warning ewWarning\">" . $sWarningMessage . "</div>";
			$_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sSuccessMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sSuccessMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sSuccessMessage . "</div>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sErrorMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sErrorMessage;
			$html .= "<div class=\"alert alert-error ewError\">" . $sErrorMessage . "</div>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo "<table class=\"ewStdTable\"><tr><td><div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div></td></tr></table>";
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p>" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Footer exists, display
			echo "<p>" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm;
		if ($this->UseTokenInUrl) {
			if ($objForm)
				return ($this->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($this->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function __construct() {
		global $conn, $Language;
		$GLOBALS["Page"] = &$this;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Parent constuctor
		parent::__construct();

		// Table object (movimientos)
		if (!isset($GLOBALS["movimientos"]) || get_class($GLOBALS["movimientos"]) == "cmovimientos") {
			$GLOBALS["movimientos"] = &$this;
			$GLOBALS["Table"] = &$GLOBALS["movimientos"];
		}

		// Table object (usuarios)
		if (!isset($GLOBALS['usuarios'])) $GLOBALS['usuarios'] = new cusuarios();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'movimientos', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->ProjectID . $this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanEdit()) {
			$Security->SaveLastUrl();
			$this->setFailureMessage($Language->Phrase("NoPermission")); // Set no permission
			$this->Page_Terminate("movimientoslist.php");
		}

		// Create form object
		$objForm = new cFormObj();
		$this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up curent action
		$this->Id->Visible = !$this->IsAdd() && !$this->IsCopy() && !$this->IsGridAdd();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter;
	var $DbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError;

		// Load key from QueryString
		if (@$_GET["Id"] <> "") {
			$this->Id->setQueryStringValue($_GET["Id"]);
		}

		// Set up Breadcrumb
		$this->SetupBreadcrumb();

		// Process form if post back
		if (@$_POST["a_edit"] <> "") {
			$this->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values
		} else {
			$this->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($this->Id->CurrentValue == "")
			$this->Page_Terminate("movimientoslist.php"); // Invalid key, return to list

		// Validate form if post back
		if (@$_POST["a_edit"] <> "") {
			if (!$this->ValidateForm()) {
				$this->CurrentAction = ""; // Form error, reset action
				$this->setFailureMessage($gsFormError);
				$this->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		}
		switch ($this->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					if ($this->getFailureMessage() == "") $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("movimientoslist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$this->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $this->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$this->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$this->ResetAttrs();
		$this->RenderRow();
	}

	// Set up starting record parameters
	function SetUpStartRec() {
		if ($this->DisplayRecs == 0)
			return;
		if ($this->IsPageRequest()) { // Validate request
			if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
				$this->StartRec = $_GET[EW_TABLE_START_REC];
				$this->setStartRecordNumber($this->StartRec);
			} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
				$PageNo = $_GET[EW_TABLE_PAGE_NO];
				if (is_numeric($PageNo)) {
					$this->StartRec = ($PageNo-1)*$this->DisplayRecs+1;
					if ($this->StartRec <= 0) {
						$this->StartRec = 1;
					} elseif ($this->StartRec >= intval(($this->TotalRecs-1)/$this->DisplayRecs)*$this->DisplayRecs+1) {
						$this->StartRec = intval(($this->TotalRecs-1)/$this->DisplayRecs)*$this->DisplayRecs+1;
					}
					$this->setStartRecordNumber($this->StartRec);
				}
			}
		}
		$this->StartRec = $this->getStartRecordNumber();

		// Check if correct start record counter
		if (!is_numeric($this->StartRec) || $this->StartRec == "") { // Avoid invalid start record counter
			$this->StartRec = 1; // Reset start record counter
			$this->setStartRecordNumber($this->StartRec);
		} elseif (intval($this->StartRec) > intval($this->TotalRecs)) { // Avoid starting record > total records
			$this->StartRec = intval(($this->TotalRecs-1)/$this->DisplayRecs)*$this->DisplayRecs+1; // Point to last page first record
			$this->setStartRecordNumber($this->StartRec);
		} elseif (($this->StartRec-1) % $this->DisplayRecs <> 0) {
			$this->StartRec = intval(($this->StartRec-1)/$this->DisplayRecs)*$this->DisplayRecs+1; // Point to page boundary
			$this->setStartRecordNumber($this->StartRec);
		}
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm;

		// Get upload data
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm;
		if (!$this->Id->FldIsDetailKey)
			$this->Id->setFormValue($objForm->GetValue("x_Id"));
		if (!$this->Fecha->FldIsDetailKey) {
			$this->Fecha->setFormValue($objForm->GetValue("x_Fecha"));
			$this->Fecha->CurrentValue = ew_UnFormatDateTime($this->Fecha->CurrentValue, 7);
		}
		if (!$this->Hora->FldIsDetailKey) {
			$this->Hora->setFormValue($objForm->GetValue("x_Hora"));
		}
		if (!$this->Tipo->FldIsDetailKey) {
			$this->Tipo->setFormValue($objForm->GetValue("x_Tipo"));
		}
		if (!$this->TipoComprobante->FldIsDetailKey) {
			$this->TipoComprobante->setFormValue($objForm->GetValue("x_TipoComprobante"));
		}
		if (!$this->Sucursal->FldIsDetailKey) {
			$this->Sucursal->setFormValue($objForm->GetValue("x_Sucursal"));
		}
		if (!$this->Usuario->FldIsDetailKey) {
			$this->Usuario->setFormValue($objForm->GetValue("x_Usuario"));
		}
		if (!$this->Monto->FldIsDetailKey) {
			$this->Monto->setFormValue($objForm->GetValue("x_Monto"));
		}
		if (!$this->Credito->FldIsDetailKey) {
			$this->Credito->setFormValue($objForm->GetValue("x_Credito"));
		}
		if (!$this->Cuota->FldIsDetailKey) {
			$this->Cuota->setFormValue($objForm->GetValue("x_Cuota"));
		}
		if (!$this->Cliente->FldIsDetailKey) {
			$this->Cliente->setFormValue($objForm->GetValue("x_Cliente"));
		}
		if (!$this->Financiera->FldIsDetailKey) {
			$this->Financiera->setFormValue($objForm->GetValue("x_Financiera"));
		}
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm;
		$this->LoadRow();
		$this->Id->CurrentValue = $this->Id->FormValue;
		$this->Fecha->CurrentValue = $this->Fecha->FormValue;
		$this->Fecha->CurrentValue = ew_UnFormatDateTime($this->Fecha->CurrentValue, 7);
		$this->Hora->CurrentValue = $this->Hora->FormValue;
		$this->Tipo->CurrentValue = $this->Tipo->FormValue;
		$this->TipoComprobante->CurrentValue = $this->TipoComprobante->FormValue;
		$this->Sucursal->CurrentValue = $this->Sucursal->FormValue;
		$this->Usuario->CurrentValue = $this->Usuario->FormValue;
		$this->Monto->CurrentValue = $this->Monto->FormValue;
		$this->Credito->CurrentValue = $this->Credito->FormValue;
		$this->Cuota->CurrentValue = $this->Cuota->FormValue;
		$this->Cliente->CurrentValue = $this->Cliente->FormValue;
		$this->Financiera->CurrentValue = $this->Financiera->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();

		// Call Row Selecting event
		$this->Row_Selecting($sFilter);

		// Load SQL based on filter
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row = &$rs->fields;
		$this->Row_Selected($row);
		$this->Id->setDbValue($rs->fields('Id'));
		$this->Fecha->setDbValue($rs->fields('Fecha'));
		$this->Hora->setDbValue($rs->fields('Hora'));
		$this->Tipo->setDbValue($rs->fields('Tipo'));
		$this->TipoComprobante->setDbValue($rs->fields('TipoComprobante'));
		$this->Sucursal->setDbValue($rs->fields('Sucursal'));
		$this->Usuario->setDbValue($rs->fields('Usuario'));
		$this->Monto->setDbValue($rs->fields('Monto'));
		$this->Credito->setDbValue($rs->fields('Credito'));
		$this->Cuota->setDbValue($rs->fields('Cuota'));
		$this->Cliente->setDbValue($rs->fields('Cliente'));
		$this->Financiera->setDbValue($rs->fields('Financiera'));
	}

	// Load DbValue from recordset
	function LoadDbValues(&$rs) {
		if (!$rs || !is_array($rs) && $rs->EOF) return;
		$row = is_array($rs) ? $rs : $rs->fields;
		$this->Id->DbValue = $row['Id'];
		$this->Fecha->DbValue = $row['Fecha'];
		$this->Hora->DbValue = $row['Hora'];
		$this->Tipo->DbValue = $row['Tipo'];
		$this->TipoComprobante->DbValue = $row['TipoComprobante'];
		$this->Sucursal->DbValue = $row['Sucursal'];
		$this->Usuario->DbValue = $row['Usuario'];
		$this->Monto->DbValue = $row['Monto'];
		$this->Credito->DbValue = $row['Credito'];
		$this->Cuota->DbValue = $row['Cuota'];
		$this->Cliente->DbValue = $row['Cliente'];
		$this->Financiera->DbValue = $row['Financiera'];
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language;
		global $gsLanguage;

		// Initialize URLs
		// Convert decimal values if posted back

		if ($this->Monto->FormValue == $this->Monto->CurrentValue && is_numeric(ew_StrToFloat($this->Monto->CurrentValue)))
			$this->Monto->CurrentValue = ew_StrToFloat($this->Monto->CurrentValue);

		// Call Row_Rendering event
		$this->Row_Rendering();

		// Common render codes for all row types
		// Id
		// Fecha
		// Hora
		// Tipo
		// TipoComprobante
		// Sucursal
		// Usuario
		// Monto
		// Credito
		// Cuota
		// Cliente
		// Financiera

		if ($this->RowType == EW_ROWTYPE_VIEW) { // View row

			// Id
			$this->Id->ViewValue = $this->Id->CurrentValue;
			$this->Id->ViewCustomAttributes = "";

			// Fecha
			$this->Fecha->ViewValue = $this->Fecha->CurrentValue;
			$this->Fecha->ViewValue = ew_FormatDateTime($this->Fecha->ViewValue, 7);
			$this->Fecha->ViewCustomAttributes = "";

			// Hora
			$this->Hora->ViewValue = $this->Hora->CurrentValue;
			$this->Hora->ViewCustomAttributes = "";

			// Tipo
			if (strval($this->Tipo->CurrentValue) <> "") {
				switch ($this->Tipo->CurrentValue) {
					case $this->Tipo->FldTagValue(1):
						$this->Tipo->ViewValue = $this->Tipo->FldTagCaption(1) <> "" ? $this->Tipo->FldTagCaption(1) : $this->Tipo->CurrentValue;
						break;
					case $this->Tipo->FldTagValue(2):
						$this->Tipo->ViewValue = $this->Tipo->FldTagCaption(2) <> "" ? $this->Tipo->FldTagCaption(2) : $this->Tipo->CurrentValue;
						break;
					default:
						$this->Tipo->ViewValue = $this->Tipo->CurrentValue;
				}
			} else {
				$this->Tipo->ViewValue = NULL;
			}
			$this->Tipo->ViewCustomAttributes = "";

			// TipoComprobante
			if (strval($this->TipoComprobante->CurrentValue) <> "") {
				switch ($this->TipoComprobante->CurrentValue) {
					case $this->TipoComprobante->FldTagValue(1):
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->FldTagCaption(1) <> "" ? $this->TipoComprobante->FldTagCaption(1) : $this->TipoComprobante->CurrentValue;
						break;
					case $this->TipoComprobante->FldTagValue(2):
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->FldTagCaption(2) <> "" ? $this->TipoComprobante->FldTagCaption(2) : $this->TipoComprobante->CurrentValue;
						break;
					case $this->TipoComprobante->FldTagValue(3):
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->FldTagCaption(3) <> "" ? $this->TipoComprobante->FldTagCaption(3) : $this->TipoComprobante->CurrentValue;
						break;
					case $this->TipoComprobante->FldTagValue(4):
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->FldTagCaption(4) <> "" ? $this->TipoComprobante->FldTagCaption(4) : $this->TipoComprobante->CurrentValue;
						break;
					case $this->TipoComprobante->FldTagValue(5):
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->FldTagCaption(5) <> "" ? $this->TipoComprobante->FldTagCaption(5) : $this->TipoComprobante->CurrentValue;
						break;
					case $this->TipoComprobante->FldTagValue(6):
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->FldTagCaption(6) <> "" ? $this->TipoComprobante->FldTagCaption(6) : $this->TipoComprobante->CurrentValue;
						break;
					default:
						$this->TipoComprobante->ViewValue = $this->TipoComprobante->CurrentValue;
				}
			} else {
				$this->TipoComprobante->ViewValue = NULL;
			}
			$this->TipoComprobante->ViewCustomAttributes = "";

			// Sucursal
			if (strval($this->Sucursal->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Sucursal->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `sucursales`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Sucursal, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Sucursal->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Sucursal->ViewValue = $this->Sucursal->CurrentValue;
				}
			} else {
				$this->Sucursal->ViewValue = NULL;
			}
			$this->Sucursal->ViewCustomAttributes = "";

			// Usuario
			$this->Usuario->ViewValue = $this->Usuario->CurrentValue;
			$this->Usuario->ViewCustomAttributes = "";

			// Monto
			$this->Monto->ViewValue = $this->Monto->CurrentValue;
			$this->Monto->ViewCustomAttributes = "";

			// Credito
			$this->Credito->ViewValue = $this->Credito->CurrentValue;
			$this->Credito->ViewCustomAttributes = "";

			// Cuota
			$this->Cuota->ViewValue = $this->Cuota->CurrentValue;
			$this->Cuota->ViewCustomAttributes = "";

			// Cliente
			if (strval($this->Cliente->CurrentValue) <> "") {
				$sFilterWrk = "`Dni`" . ew_SearchString("=", $this->Cliente->CurrentValue, EW_DATATYPE_STRING);
			$sSqlWrk = "SELECT `Dni`, `Apellido` AS `DispFld`, `Nombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `clientes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Cliente, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Cliente->ViewValue = $rswrk->fields('DispFld');
					$this->Cliente->ViewValue .= ew_ValueSeparator(1,$this->Cliente) . $rswrk->fields('Disp2Fld');
					$rswrk->Close();
				} else {
					$this->Cliente->ViewValue = $this->Cliente->CurrentValue;
				}
			} else {
				$this->Cliente->ViewValue = NULL;
			}
			$this->Cliente->ViewCustomAttributes = "";

			// Financiera
			if (strval($this->Financiera->CurrentValue) <> "") {
				$sFilterWrk = "`id`" . ew_SearchString("=", $this->Financiera->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `tipocreditos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Financiera, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Financiera->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->Financiera->ViewValue = $this->Financiera->CurrentValue;
				}
			} else {
				$this->Financiera->ViewValue = NULL;
			}
			$this->Financiera->ViewCustomAttributes = "";

			// Id
			$this->Id->LinkCustomAttributes = "";
			$this->Id->HrefValue = "";
			$this->Id->TooltipValue = "";

			// Fecha
			$this->Fecha->LinkCustomAttributes = "";
			$this->Fecha->HrefValue = "";
			$this->Fecha->TooltipValue = "";

			// Hora
			$this->Hora->LinkCustomAttributes = "";
			$this->Hora->HrefValue = "";
			$this->Hora->TooltipValue = "";

			// Tipo
			$this->Tipo->LinkCustomAttributes = "";
			$this->Tipo->HrefValue = "";
			$this->Tipo->TooltipValue = "";

			// TipoComprobante
			$this->TipoComprobante->LinkCustomAttributes = "";
			$this->TipoComprobante->HrefValue = "";
			$this->TipoComprobante->TooltipValue = "";

			// Sucursal
			$this->Sucursal->LinkCustomAttributes = "";
			$this->Sucursal->HrefValue = "";
			$this->Sucursal->TooltipValue = "";

			// Usuario
			$this->Usuario->LinkCustomAttributes = "";
			$this->Usuario->HrefValue = "";
			$this->Usuario->TooltipValue = "";

			// Monto
			$this->Monto->LinkCustomAttributes = "";
			$this->Monto->HrefValue = "";
			$this->Monto->TooltipValue = "";

			// Credito
			$this->Credito->LinkCustomAttributes = "";
			$this->Credito->HrefValue = "";
			$this->Credito->TooltipValue = "";

			// Cuota
			$this->Cuota->LinkCustomAttributes = "";
			$this->Cuota->HrefValue = "";
			$this->Cuota->TooltipValue = "";

			// Cliente
			$this->Cliente->LinkCustomAttributes = "";
			$this->Cliente->HrefValue = "";
			$this->Cliente->TooltipValue = "";

			// Financiera
			$this->Financiera->LinkCustomAttributes = "";
			$this->Financiera->HrefValue = "";
			$this->Financiera->TooltipValue = "";
		} elseif ($this->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// Id
			$this->Id->EditCustomAttributes = "";
			$this->Id->EditValue = $this->Id->CurrentValue;
			$this->Id->ViewCustomAttributes = "";

			// Fecha
			$this->Fecha->EditCustomAttributes = "";
			$this->Fecha->EditValue = ew_HtmlEncode(ew_FormatDateTime($this->Fecha->CurrentValue, 7));
			$this->Fecha->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Fecha->FldCaption()));

			// Hora
			$this->Hora->EditCustomAttributes = "";
			$this->Hora->EditValue = ew_HtmlEncode($this->Hora->CurrentValue);
			$this->Hora->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Hora->FldCaption()));

			// Tipo
			$this->Tipo->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->Tipo->FldTagValue(1), $this->Tipo->FldTagCaption(1) <> "" ? $this->Tipo->FldTagCaption(1) : $this->Tipo->FldTagValue(1));
			$arwrk[] = array($this->Tipo->FldTagValue(2), $this->Tipo->FldTagCaption(2) <> "" ? $this->Tipo->FldTagCaption(2) : $this->Tipo->FldTagValue(2));
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$this->Tipo->EditValue = $arwrk;

			// TipoComprobante
			$this->TipoComprobante->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->TipoComprobante->FldTagValue(1), $this->TipoComprobante->FldTagCaption(1) <> "" ? $this->TipoComprobante->FldTagCaption(1) : $this->TipoComprobante->FldTagValue(1));
			$arwrk[] = array($this->TipoComprobante->FldTagValue(2), $this->TipoComprobante->FldTagCaption(2) <> "" ? $this->TipoComprobante->FldTagCaption(2) : $this->TipoComprobante->FldTagValue(2));
			$arwrk[] = array($this->TipoComprobante->FldTagValue(3), $this->TipoComprobante->FldTagCaption(3) <> "" ? $this->TipoComprobante->FldTagCaption(3) : $this->TipoComprobante->FldTagValue(3));
			$arwrk[] = array($this->TipoComprobante->FldTagValue(4), $this->TipoComprobante->FldTagCaption(4) <> "" ? $this->TipoComprobante->FldTagCaption(4) : $this->TipoComprobante->FldTagValue(4));
			$arwrk[] = array($this->TipoComprobante->FldTagValue(5), $this->TipoComprobante->FldTagCaption(5) <> "" ? $this->TipoComprobante->FldTagCaption(5) : $this->TipoComprobante->FldTagValue(5));
			$arwrk[] = array($this->TipoComprobante->FldTagValue(6), $this->TipoComprobante->FldTagCaption(6) <> "" ? $this->TipoComprobante->FldTagCaption(6) : $this->TipoComprobante->FldTagValue(6));
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$this->TipoComprobante->EditValue = $arwrk;

			// Sucursal
			$this->Sucursal->EditCustomAttributes = "";
			$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `sucursales`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Sucursal, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Sucursal->EditValue = $arwrk;

			// Usuario
			$this->Usuario->EditCustomAttributes = "";
			$this->Usuario->EditValue = ew_HtmlEncode($this->Usuario->CurrentValue);
			$this->Usuario->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Usuario->FldCaption()));

			// Monto
			$this->Monto->EditCustomAttributes = "";
			$this->Monto->EditValue = ew_HtmlEncode($this->Monto->CurrentValue);
			$this->Monto->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Monto->FldCaption()));
			if (strval($this->Monto->EditValue) <> "" && is_numeric($this->Monto->EditValue)) $this->Monto->EditValue = ew_FormatNumber($this->Monto->EditValue, -2, -1, -2, 0);

			// Credito
			$this->Credito->EditCustomAttributes = "";
			$this->Credito->EditValue = ew_HtmlEncode($this->Credito->CurrentValue);
			$this->Credito->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Credito->FldCaption()));

			// Cuota
			$this->Cuota->EditCustomAttributes = "";
			$this->Cuota->EditValue = ew_HtmlEncode($this->Cuota->CurrentValue);
			$this->Cuota->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->Cuota->FldCaption()));

			// Cliente
			$this->Cliente->EditCustomAttributes = "";
			$sFilterWrk = "";
			$sSqlWrk = "SELECT `Dni`, `Apellido` AS `DispFld`, `Nombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `clientes`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Cliente, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Cliente->EditValue = $arwrk;

			// Financiera
			$this->Financiera->EditCustomAttributes = "";
			$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `Nombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `tipocreditos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->Financiera, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->Financiera->EditValue = $arwrk;

			// Edit refer script
			// Id

			$this->Id->HrefValue = "";

			// Fecha
			$this->Fecha->HrefValue = "";

			// Hora
			$this->Hora->HrefValue = "";

			// Tipo
			$this->Tipo->HrefValue = "";

			// TipoComprobante
			$this->TipoComprobante->HrefValue = "";

			// Sucursal
			$this->Sucursal->HrefValue = "";

			// Usuario
			$this->Usuario->HrefValue = "";

			// Monto
			$this->Monto->HrefValue = "";

			// Credito
			$this->Credito->HrefValue = "";

			// Cuota
			$this->Cuota->HrefValue = "";

			// Cliente
			$this->Cliente->HrefValue = "";

			// Financiera
			$this->Financiera->HrefValue = "";
		}
		if ($this->RowType == EW_ROWTYPE_ADD ||
			$this->RowType == EW_ROWTYPE_EDIT ||
			$this->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$this->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($this->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$this->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!$this->Fecha->FldIsDetailKey && !is_null($this->Fecha->FormValue) && $this->Fecha->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $this->Fecha->FldCaption());
		}
		if (!ew_CheckEuroDate($this->Fecha->FormValue)) {
			ew_AddMessage($gsFormError, $this->Fecha->FldErrMsg());
		}
		if (!$this->Tipo->FldIsDetailKey && !is_null($this->Tipo->FormValue) && $this->Tipo->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $this->Tipo->FldCaption());
		}
		if (!$this->Sucursal->FldIsDetailKey && !is_null($this->Sucursal->FormValue) && $this->Sucursal->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $this->Sucursal->FldCaption());
		}
		if (!ew_CheckInteger($this->Usuario->FormValue)) {
			ew_AddMessage($gsFormError, $this->Usuario->FldErrMsg());
		}
		if (!$this->Monto->FldIsDetailKey && !is_null($this->Monto->FormValue) && $this->Monto->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $this->Monto->FldCaption());
		}
		if (!ew_CheckNumber($this->Monto->FormValue)) {
			ew_AddMessage($gsFormError, $this->Monto->FldErrMsg());
		}
		if (!ew_CheckInteger($this->Credito->FormValue)) {
			ew_AddMessage($gsFormError, $this->Credito->FldErrMsg());
		}
		if (!ew_CheckInteger($this->Cuota->FormValue)) {
			ew_AddMessage($gsFormError, $this->Cuota->FldErrMsg());
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Save old values
			$rsold = &$rs->fields;
			$this->LoadDbValues($rsold);
			$rsnew = array();

			// Fecha
			$this->Fecha->SetDbValueDef($rsnew, ew_UnFormatDateTime($this->Fecha->CurrentValue, 7), ew_CurrentDate(), $this->Fecha->ReadOnly);

			// Hora
			$this->Hora->SetDbValueDef($rsnew, $this->Hora->CurrentValue, NULL, $this->Hora->ReadOnly);

			// Tipo
			$this->Tipo->SetDbValueDef($rsnew, $this->Tipo->CurrentValue, 0, $this->Tipo->ReadOnly);

			// TipoComprobante
			$this->TipoComprobante->SetDbValueDef($rsnew, $this->TipoComprobante->CurrentValue, NULL, $this->TipoComprobante->ReadOnly);

			// Sucursal
			$this->Sucursal->SetDbValueDef($rsnew, $this->Sucursal->CurrentValue, 0, $this->Sucursal->ReadOnly);

			// Usuario
			$this->Usuario->SetDbValueDef($rsnew, $this->Usuario->CurrentValue, NULL, $this->Usuario->ReadOnly);

			// Monto
			$this->Monto->SetDbValueDef($rsnew, $this->Monto->CurrentValue, 0, $this->Monto->ReadOnly);

			// Credito
			$this->Credito->SetDbValueDef($rsnew, $this->Credito->CurrentValue, NULL, $this->Credito->ReadOnly);

			// Cuota
			$this->Cuota->SetDbValueDef($rsnew, $this->Cuota->CurrentValue, NULL, $this->Cuota->ReadOnly);

			// Cliente
			$this->Cliente->SetDbValueDef($rsnew, $this->Cliente->CurrentValue, NULL, $this->Cliente->ReadOnly);

			// Financiera
			$this->Financiera->SetDbValueDef($rsnew, $this->Financiera->CurrentValue, NULL, $this->Financiera->ReadOnly);

			// Call Row Updating event
			$bUpdateRow = $this->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
				$conn->raiseErrorFn = 'ew_ErrorFn';
				if (count($rsnew) > 0)
					$EditRow = $this->Update($rsnew, "", $rsold);
				else
					$EditRow = TRUE; // No field to update
				$conn->raiseErrorFn = '';
				if ($EditRow) {
				}
			} else {
				if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

					// Use the message, do nothing
				} elseif ($this->CancelMessage <> "") {
					$this->setFailureMessage($this->CancelMessage);
					$this->CancelMessage = "";
				} else {
					$this->setFailureMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$this->Row_Updated($rsold, $rsnew);
		$rs->Close();
		return $EditRow;
	}

	// Set up Breadcrumb
	function SetupBreadcrumb() {
		global $Breadcrumb, $Language;
		$Breadcrumb = new cBreadcrumb();
		$Breadcrumb->Add("list", $this->TableVar, "movimientoslist.php", $this->TableVar, TRUE);
		$PageId = "edit";
		$Breadcrumb->Add("edit", $PageId, ew_CurrentUrl());
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'|'warning'
	function Message_Showing(&$msg, $type) {
		if ($type == 'success') {

			//$msg = "your success message";
		} elseif ($type == 'failure') {

			//$msg = "your failure message";
		} elseif ($type == 'warning') {

			//$msg = "your warning message";
		} else {

			//$msg = "your message";
		}
	}

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
<?php ew_Header(FALSE) ?>
<?php

// Create page object
if (!isset($movimientos_edit)) $movimientos_edit = new cmovimientos_edit();

// Page init
$movimientos_edit->Page_Init();

// Page main
$movimientos_edit->Page_Main();

// Global Page Rendering event (in userfn*.php)
Page_Rendering();

// Page Rendering event
$movimientos_edit->Page_Render();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">

// Page object
var movimientos_edit = new ew_Page("movimientos_edit");
movimientos_edit.PageID = "edit"; // Page ID
var EW_PAGE_ID = movimientos_edit.PageID; // For backward compatibility

// Form object
var fmovimientosedit = new ew_Form("fmovimientosedit");

// Validate form
fmovimientosedit.Validate = function() {
	if (!this.ValidateRequired)
		return true; // Ignore validation
	var $ = jQuery, fobj = this.GetForm(), $fobj = $(fobj);
	this.PostAutoSuggest();
	if ($fobj.find("#a_confirm").val() == "F")
		return true;
	var elm, felm, uelm, addcnt = 0;
	var $k = $fobj.find("#" + this.FormKeyCountName); // Get key_count
	var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
	var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
	var gridinsert = $fobj.find("#a_list").val() == "gridinsert";
	for (var i = startcnt; i <= rowcnt; i++) {
		var infix = ($k[0]) ? String(i) : "";
		$fobj.data("rowindex", infix);
			elm = this.GetElements("x" + infix + "_Fecha");
			if (elm && !ew_HasValue(elm))
				return this.OnError(elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($movimientos->Fecha->FldCaption()) ?>");
			elm = this.GetElements("x" + infix + "_Fecha");
			if (elm && !ew_CheckEuroDate(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($movimientos->Fecha->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Tipo");
			if (elm && !ew_HasValue(elm))
				return this.OnError(elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($movimientos->Tipo->FldCaption()) ?>");
			elm = this.GetElements("x" + infix + "_Sucursal");
			if (elm && !ew_HasValue(elm))
				return this.OnError(elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($movimientos->Sucursal->FldCaption()) ?>");
			elm = this.GetElements("x" + infix + "_Usuario");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($movimientos->Usuario->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Monto");
			if (elm && !ew_HasValue(elm))
				return this.OnError(elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($movimientos->Monto->FldCaption()) ?>");
			elm = this.GetElements("x" + infix + "_Monto");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($movimientos->Monto->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Credito");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($movimientos->Credito->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_Cuota");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($movimientos->Cuota->FldErrMsg()) ?>");

			// Set up row object
			ew_ElementsToRow(fobj);

			// Fire Form_CustomValidate event
			if (!this.Form_CustomValidate(fobj))
				return false;
	}

	// Process detail forms
	var dfs = $fobj.find("input[name='detailpage']").get();
	for (var i = 0; i < dfs.length; i++) {
		var df = dfs[i], val = df.value;
		if (val && ewForms[val])
			if (!ewForms[val].Validate())
				return false;
	}
	return true;
}

// Form_CustomValidate event
fmovimientosedit.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }

// Use JavaScript validation or not
<?php if (EW_CLIENT_VALIDATE) { ?>
fmovimientosedit.ValidateRequired = true;
<?php } else { ?>
fmovimientosedit.ValidateRequired = false; 
<?php } ?>

// Dynamic selection lists
fmovimientosedit.Lists["x_Sucursal"] = {"LinkField":"x_id","Ajax":null,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fmovimientosedit.Lists["x_Cliente"] = {"LinkField":"x_Dni","Ajax":null,"AutoFill":false,"DisplayFields":["x_Apellido","x_Nombre","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fmovimientosedit.Lists["x_Financiera"] = {"LinkField":"x_id","Ajax":null,"AutoFill":false,"DisplayFields":["x_Nombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};

// Form object for search
</script>
<script type="text/javascript">

// Write your client script here, no need to add script tags.
</script>
<?php $Breadcrumb->Render(); ?>
<?php $movimientos_edit->ShowPageHeader(); ?>
<?php
$movimientos_edit->ShowMessage();
?>
<form name="fmovimientosedit" id="fmovimientosedit" class="ewForm form-horizontal" action="<?php echo ew_CurrentPage() ?>" method="post">
<input type="hidden" name="t" value="movimientos">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table class="ewGrid"><tr><td>
<table id="tbl_movimientosedit" class="table table-bordered table-striped">
<?php if ($movimientos->Id->Visible) { // Id ?>
	<tr id="r_Id">
		<td><span id="elh_movimientos_Id"><?php echo $movimientos->Id->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Id->CellAttributes() ?>>
<span id="el_movimientos_Id" class="control-group">
<span<?php echo $movimientos->Id->ViewAttributes() ?>>
<?php echo $movimientos->Id->EditValue ?></span>
</span>
<input type="hidden" data-field="x_Id" name="x_Id" id="x_Id" value="<?php echo ew_HtmlEncode($movimientos->Id->CurrentValue) ?>">
<?php echo $movimientos->Id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Fecha->Visible) { // Fecha ?>
	<tr id="r_Fecha">
		<td><span id="elh_movimientos_Fecha"><?php echo $movimientos->Fecha->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></span></td>
		<td<?php echo $movimientos->Fecha->CellAttributes() ?>>
<span id="el_movimientos_Fecha" class="control-group">
<input type="text" data-field="x_Fecha" name="x_Fecha" id="x_Fecha" placeholder="<?php echo $movimientos->Fecha->PlaceHolder ?>" value="<?php echo $movimientos->Fecha->EditValue ?>"<?php echo $movimientos->Fecha->EditAttributes() ?>>
<?php if (!$movimientos->Fecha->ReadOnly && !$movimientos->Fecha->Disabled && @$movimientos->Fecha->EditAttrs["readonly"] == "" && @$movimientos->Fecha->EditAttrs["disabled"] == "") { ?>
<button id="cal_x_Fecha" name="cal_x_Fecha" class="btn" type="button"><img src="phpimages/calendar.png" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="border: 0;"></button><script type="text/javascript">
ew_CreateCalendar("fmovimientosedit", "x_Fecha", "%d/%m/%Y");
</script>
<?php } ?>
</span>
<?php echo $movimientos->Fecha->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Hora->Visible) { // Hora ?>
	<tr id="r_Hora">
		<td><span id="elh_movimientos_Hora"><?php echo $movimientos->Hora->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Hora->CellAttributes() ?>>
<span id="el_movimientos_Hora" class="control-group">
<input type="text" data-field="x_Hora" name="x_Hora" id="x_Hora" size="30" maxlength="60" placeholder="<?php echo $movimientos->Hora->PlaceHolder ?>" value="<?php echo $movimientos->Hora->EditValue ?>"<?php echo $movimientos->Hora->EditAttributes() ?>>
</span>
<?php echo $movimientos->Hora->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Tipo->Visible) { // Tipo ?>
	<tr id="r_Tipo">
		<td><span id="elh_movimientos_Tipo"><?php echo $movimientos->Tipo->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></span></td>
		<td<?php echo $movimientos->Tipo->CellAttributes() ?>>
<span id="el_movimientos_Tipo" class="control-group">
<select data-field="x_Tipo" id="x_Tipo" name="x_Tipo"<?php echo $movimientos->Tipo->EditAttributes() ?>>
<?php
if (is_array($movimientos->Tipo->EditValue)) {
	$arwrk = $movimientos->Tipo->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($movimientos->Tipo->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span>
<?php echo $movimientos->Tipo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->TipoComprobante->Visible) { // TipoComprobante ?>
	<tr id="r_TipoComprobante">
		<td><span id="elh_movimientos_TipoComprobante"><?php echo $movimientos->TipoComprobante->FldCaption() ?></span></td>
		<td<?php echo $movimientos->TipoComprobante->CellAttributes() ?>>
<span id="el_movimientos_TipoComprobante" class="control-group">
<select data-field="x_TipoComprobante" id="x_TipoComprobante" name="x_TipoComprobante"<?php echo $movimientos->TipoComprobante->EditAttributes() ?>>
<?php
if (is_array($movimientos->TipoComprobante->EditValue)) {
	$arwrk = $movimientos->TipoComprobante->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($movimientos->TipoComprobante->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span>
<?php echo $movimientos->TipoComprobante->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Sucursal->Visible) { // Sucursal ?>
	<tr id="r_Sucursal">
		<td><span id="elh_movimientos_Sucursal"><?php echo $movimientos->Sucursal->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></span></td>
		<td<?php echo $movimientos->Sucursal->CellAttributes() ?>>
<span id="el_movimientos_Sucursal" class="control-group">
<select data-field="x_Sucursal" id="x_Sucursal" name="x_Sucursal"<?php echo $movimientos->Sucursal->EditAttributes() ?>>
<?php
if (is_array($movimientos->Sucursal->EditValue)) {
	$arwrk = $movimientos->Sucursal->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($movimientos->Sucursal->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<script type="text/javascript">
fmovimientosedit.Lists["x_Sucursal"].Options = <?php echo (is_array($movimientos->Sucursal->EditValue)) ? ew_ArrayToJson($movimientos->Sucursal->EditValue, 1) : "[]" ?>;
</script>
</span>
<?php echo $movimientos->Sucursal->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Usuario->Visible) { // Usuario ?>
	<tr id="r_Usuario">
		<td><span id="elh_movimientos_Usuario"><?php echo $movimientos->Usuario->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Usuario->CellAttributes() ?>>
<span id="el_movimientos_Usuario" class="control-group">
<input type="text" data-field="x_Usuario" name="x_Usuario" id="x_Usuario" size="30" placeholder="<?php echo $movimientos->Usuario->PlaceHolder ?>" value="<?php echo $movimientos->Usuario->EditValue ?>"<?php echo $movimientos->Usuario->EditAttributes() ?>>
</span>
<?php echo $movimientos->Usuario->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Monto->Visible) { // Monto ?>
	<tr id="r_Monto">
		<td><span id="elh_movimientos_Monto"><?php echo $movimientos->Monto->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></span></td>
		<td<?php echo $movimientos->Monto->CellAttributes() ?>>
<span id="el_movimientos_Monto" class="control-group">
<input type="text" data-field="x_Monto" name="x_Monto" id="x_Monto" size="30" placeholder="<?php echo $movimientos->Monto->PlaceHolder ?>" value="<?php echo $movimientos->Monto->EditValue ?>"<?php echo $movimientos->Monto->EditAttributes() ?>>
</span>
<?php echo $movimientos->Monto->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Credito->Visible) { // Credito ?>
	<tr id="r_Credito">
		<td><span id="elh_movimientos_Credito"><?php echo $movimientos->Credito->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Credito->CellAttributes() ?>>
<span id="el_movimientos_Credito" class="control-group">
<input type="text" data-field="x_Credito" name="x_Credito" id="x_Credito" size="30" placeholder="<?php echo $movimientos->Credito->PlaceHolder ?>" value="<?php echo $movimientos->Credito->EditValue ?>"<?php echo $movimientos->Credito->EditAttributes() ?>>
</span>
<?php echo $movimientos->Credito->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Cuota->Visible) { // Cuota ?>
	<tr id="r_Cuota">
		<td><span id="elh_movimientos_Cuota"><?php echo $movimientos->Cuota->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Cuota->CellAttributes() ?>>
<span id="el_movimientos_Cuota" class="control-group">
<input type="text" data-field="x_Cuota" name="x_Cuota" id="x_Cuota" size="30" placeholder="<?php echo $movimientos->Cuota->PlaceHolder ?>" value="<?php echo $movimientos->Cuota->EditValue ?>"<?php echo $movimientos->Cuota->EditAttributes() ?>>
</span>
<?php echo $movimientos->Cuota->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Cliente->Visible) { // Cliente ?>
	<tr id="r_Cliente">
		<td><span id="elh_movimientos_Cliente"><?php echo $movimientos->Cliente->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Cliente->CellAttributes() ?>>
<span id="el_movimientos_Cliente" class="control-group">
<select data-field="x_Cliente" id="x_Cliente" name="x_Cliente"<?php echo $movimientos->Cliente->EditAttributes() ?>>
<?php
if (is_array($movimientos->Cliente->EditValue)) {
	$arwrk = $movimientos->Cliente->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($movimientos->Cliente->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
<?php echo ew_ValueSeparator(1,$movimientos->Cliente) ?><?php echo $arwrk[$rowcntwrk][2] ?>
<?php } ?>
</option>
<?php
	}
}
?>
</select>
<script type="text/javascript">
fmovimientosedit.Lists["x_Cliente"].Options = <?php echo (is_array($movimientos->Cliente->EditValue)) ? ew_ArrayToJson($movimientos->Cliente->EditValue, 1) : "[]" ?>;
</script>
</span>
<?php echo $movimientos->Cliente->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($movimientos->Financiera->Visible) { // Financiera ?>
	<tr id="r_Financiera">
		<td><span id="elh_movimientos_Financiera"><?php echo $movimientos->Financiera->FldCaption() ?></span></td>
		<td<?php echo $movimientos->Financiera->CellAttributes() ?>>
<span id="el_movimientos_Financiera" class="control-group">
<select data-field="x_Financiera" id="x_Financiera" name="x_Financiera"<?php echo $movimientos->Financiera->EditAttributes() ?>>
<?php
if (is_array($movimientos->Financiera->EditValue)) {
	$arwrk = $movimientos->Financiera->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($movimientos->Financiera->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<script type="text/javascript">
fmovimientosedit.Lists["x_Financiera"].Options = <?php echo (is_array($movimientos->Financiera->EditValue)) ? ew_ArrayToJson($movimientos->Financiera->EditValue, 1) : "[]" ?>;
</script>
</span>
<?php echo $movimientos->Financiera->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</td></tr></table>
<button class="btn btn-primary ewButton" name="btnAction" id="btnAction" type="submit"><?php echo $Language->Phrase("EditBtn") ?></button>
</form>
<script type="text/javascript">
fmovimientosedit.Init();
<?php if (EW_MOBILE_REFLOW && ew_IsMobile()) { ?>
ew_Reflow();
<?php } ?>
</script>
<?php
$movimientos_edit->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");

</script>
<?php include_once "footer.php" ?>
<?php
$movimientos_edit->Page_Terminate();
?>
